package br.com.educa.util;

import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;


public class EnviadorDeEmail {

	public static void main(String[] args) {
		EnviadorDeEmail email = new EnviadorDeEmail();
		email.sendPersonalMessage("filipe.marinho.brito@gmail.com", "teste cabuloso", "foi msmo");
	}
	
    public void sendPersonalMessage(final String mailTo, final String mensagem, final String assunto){

    	
    	JavaMailSenderImpl mailTemplate = new JavaMailSenderImpl();
    	mailTemplate.setDefaultEncoding("UTF-8");
    	Properties props=new Properties();
    	props.put("mail.smtp.starttls.enable","true");
    	mailTemplate.setJavaMailProperties(props);
    	mailTemplate.setHost("smtpsrv.mj.gov.br");
    	mailTemplate.setPassword("springroo");
    	mailTemplate.setPort(25);
    	mailTemplate.setProtocol("smtp");
    	mailTemplate.setUsername("spring.roo.sender");
    	
    	final SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    	simpleMailMessage.setFrom("MJ");
    	simpleMailMessage.setSubject("[MJ][DEPAID][SISTEMAS]");
    	
    	
    	mailTemplate.send(new MimeMessagePreparator() {
    		   public void prepare(MimeMessage mimeMessage) throws MessagingException {
    			     MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
    			     message.setFrom(simpleMailMessage.getFrom());
    			     message.setTo(mailTo);
    			     message.setSubject(assunto);
    			     message.setText(mensagem, true);
    			   }
    			 });
    }
	
}
